<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>notebookAndCellPhoneAndPadInfos</title>
    <style>
    table{border-collapse:collapse;border-spacing:0;border-left:1px solid #888;border-top:1px solid #888;margin: auto}
    th,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;}
    th{font-weight:bold;}
    body{text-align: center}
    </style>
    {% load static %}
    <script type='text/javascript' src="/static/js/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("input[name='addInfo']").click(function(){
                var name = $("#machineName").val();
                var info = $("#machineInfo").val();
                var csrf = $("input[name='csrfmiddlewaretoken']").val();
                $.ajax({
                    url:'/addMachineInfo/',
                    type:'POST',
                    data:{name:name,info:info,csrfmiddlewaretoken:csrf},
                    success:function (data) {
                        if(data == '1'){
                            alert('添加成功');
                            window.location.reload();
                        }else{
                            alert('添加失败')
                            window.location.reload();
                        }
                    }
                });
            });
            $("input[name='deleteChecked']").click(function(){
                var ids = '0';
                $.each($("input:checkbox:checked"),function () {
                    ids = ids + '-'+$(this).val();
                })
                if(ids.length == 0){
                    return false;
                }
                var csrf = $("input[name='csrfmiddlewaretoken']").val();
                $.ajax({
                    url:'/delMachineInfo/',
                    type:'POST',
                    data:{ids:ids,csrfmiddlewaretoken:csrf},
                    success:function (data) {
                        if(data == '1'){
                            alert('删除成功');
                            window.location.reload();
                        }else{
                            alert('删除失败')
                            window.location.reload();
                        }
                    }
                });
            });
        });
    </script>
</head>
<body>

    <table style="font-size: small;width: 120%">
        <tr>
            <td colspan="3">测试机信息</td>
        </tr>
        {% for info in infos %}
        <tr>
            <td style="width: 60px">
                {{ forloop.counter }}
                <input type="checkbox" value="{{ info.id }}" name="infoId"/>
            </td>
            <td>{{ info.name }}</td>
            <td style="text-align: left">{{ info.mainInfo }}</td>
        </tr>
        {% endfor %}
    <tr>
        <td colspan="3"><input type="button" value="删除选中" name="deleteChecked"/></td>
    </tr>
    </table><br>
    <table style="font-size: small">
        <tr>
            <td>机器类型</td>
            <td><input size="100px" name="machineName"  id="machineName"></td>
        </tr>
        <tr>
            <td>笔记本信息</td>
            <td>
                <textarea rows="5" cols="91" name="machineInfo" id="machineInfo"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" value="提交" name="addInfo"/></td>
        </tr>
    </table>
{% csrf_token %}
</body>
</html>